package cn.zymall.common.utils.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @author xuxianda
 * @Description: 响应前端结果集
 * @date 2020/8/23 10:34
 * @Copyright
 * @return
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Accessors(chain = true)
public class HttpResult<T> {

    private Integer code;

    private String msg;

    private T data;

    private Date date = new Date();

    public HttpResult<T> success(String msg) {
        return new HttpResult<T>().setMsg(msg).setCode(200);
    }

    public HttpResult<T> success(String msg, T data) {
        return new HttpResult<T>().setMsg(msg).setData(data).setCode(200);
    }

    public HttpResult<T> success(Integer code, String msg, T data) {
        return new HttpResult<T>().setMsg(msg).setData(data).setCode(code);
    }

    public HttpResult<T> fail(String msg) {
        return new HttpResult<T>().setMsg(msg).setCode(500);
    }

    public HttpResult<T> fail(String msg, T data) {
        return new HttpResult<T>().setMsg(msg).setData(data).setCode(500);
    }

    public HttpResult<T> fail(Integer code, String msg, T data) {
        return new HttpResult<T>().setMsg(msg).setData(data).setCode(code);
    }

}
